package io.github.mobodev.accessbilityservicetest;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

/**
 * Created by bshao on 5/5/16.
 */
public class PreferencesController {
    private static final String ENABLE_DUAL_SIM_PREFERENCE_KEY = "com.nanosoft.application.media.controller.ENABLE_DUAL_SIM_PREFERENCE_KEY";
    private static final String ENABLE_HEADSET_PREFERENCE_KEY = "com.nanosoft.application.media.controller.ENABLE_HEADSET_PREFERENCE_KEY";
    private static final String ENABLE_PROXIMITY_SENSOR_PREFERENCE_KEY = "com.nanosoft.application.media.controller.ENABLE_PROXIMITY_SENSOR_PREFERENCE_KEY";
    private static final String END_CALL_VIBRATION_COUNT_PREFERENCE_KEY = "com.nanosoft.application.media.controller.END_CALL_VIBRATION_COUNT_PREFERENCE_KEY";
    private static final String END_CALL_VIBRATION_DURATION_PREFERENCE_KEY = "com.nanosoft.application.media.controller.END_CALL_VIBRATION_DURATION_PREFERENCE_KEY";
    private static final String IS_FIRST_RUN_PREFERENCE_KEY = "com.nanosoft.application.media.controller.IS_FIRST_RUN";
    private static final String OUTGOING_CALL_STARTED_PREFERENCE_KEY = "com.nanosoft.application.media.controller.OUTGOING_CALL_STARTED_PREFERENCE_KEY";
    private static final String START_CALL_VIBRATION_COUNT_PREFERENCE_KEY = "com.nanosoft.application.media.controller.START_CALL_VIBRATION_COUNT_PREFERENCE_KEY";
    private static final String START_CALL_VIBRATION_DURATION_PREFERENCE_KEY = "com.nanosoft.application.media.controller.START_CALL_VIBRATION_DURATION_PREFERENCE_KEY";
    private static final String VIBRATE_ON_CALL_END_PREFERENCE_KEY = "com.nanosoft.application.media.controller.VIBRATE_ON_CALL_END_PREFERENCE_KEY";
    private static final String VIBRATE_ON_CALL_START_PREFERENCE_KEY = "com.nanosoft.application.media.controller.VIBRATE_ON_CALL_START_PREFERENCE_KEY";

    public static void setIsFirstRun(Context context, boolean value) {
        SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
        editor.putBoolean(IS_FIRST_RUN_PREFERENCE_KEY, value);
        editor.commit();
    }

    public static boolean getIsFirstRun(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(IS_FIRST_RUN_PREFERENCE_KEY, true);
    }

    public static void setOutGoingCallStarted(Context context, boolean value) {
        SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
        editor.putBoolean(OUTGOING_CALL_STARTED_PREFERENCE_KEY, value);
        editor.commit();
    }

    public static boolean getOutGoingCallStarted(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(OUTGOING_CALL_STARTED_PREFERENCE_KEY, false);
    }

    public static void setVibrateOnCallStart(Context context, boolean value) {
        SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
        editor.putBoolean(VIBRATE_ON_CALL_START_PREFERENCE_KEY, value);
        editor.commit();
    }

    public static boolean getVibrateOnCallStart(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(VIBRATE_ON_CALL_START_PREFERENCE_KEY, true);
    }

    public static void setVibrateOnCallEnd(Context context, boolean value) {
        SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
        editor.putBoolean(VIBRATE_ON_CALL_END_PREFERENCE_KEY, value);
        editor.commit();
    }

    public static boolean getVibrateOnCallEnd(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(VIBRATE_ON_CALL_END_PREFERENCE_KEY, true);
    }

    public static void setEnableHeadset(Context context, boolean value) {
        SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
        editor.putBoolean(ENABLE_HEADSET_PREFERENCE_KEY, value);
        editor.commit();
    }

    public static boolean getEnableHeadset(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(ENABLE_HEADSET_PREFERENCE_KEY, true);
    }

    public static void setEnableProximitySensor(Context context, boolean value) {
        SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
        editor.putBoolean(ENABLE_PROXIMITY_SENSOR_PREFERENCE_KEY, value);
        editor.commit();
    }

    public static boolean getEnableProximitySensor(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(ENABLE_PROXIMITY_SENSOR_PREFERENCE_KEY, true);
    }

    public static void setEnableDualSim(Context context, boolean value) {
        SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
        editor.putBoolean(ENABLE_DUAL_SIM_PREFERENCE_KEY, value);
        editor.commit();
    }

    public static boolean getEnableDualSim(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(ENABLE_DUAL_SIM_PREFERENCE_KEY, false);
    }

    public static void setStartCallVibrationDuration(Context context, int value) {
        SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
        editor.putInt(START_CALL_VIBRATION_DURATION_PREFERENCE_KEY, value);
        editor.commit();
    }

    public static int getStartCallVibrationDuration(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getInt(START_CALL_VIBRATION_DURATION_PREFERENCE_KEY, 1);
    }

    public static void setEndCallVibrationDuration(Context context, int value) {
        SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
        editor.putInt(END_CALL_VIBRATION_DURATION_PREFERENCE_KEY, value);
        editor.commit();
    }

    public static int getEndCallVibrationDuration(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getInt(END_CALL_VIBRATION_DURATION_PREFERENCE_KEY, 1);
    }

    public static void setStartCallVibrationCount(Context context, int value) {
        SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
        editor.putInt(START_CALL_VIBRATION_COUNT_PREFERENCE_KEY, value);
        editor.commit();
    }

    public static int getStartCallVibrationCount(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getInt(START_CALL_VIBRATION_COUNT_PREFERENCE_KEY, 0);
    }

    public static void setEndCallVibrationCount(Context context, int value) {
        SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
        editor.putInt(END_CALL_VIBRATION_COUNT_PREFERENCE_KEY, value);
        editor.commit();
    }

    public static int getEndCallVibrationCount(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getInt(END_CALL_VIBRATION_COUNT_PREFERENCE_KEY, 1);
    }
}
